package battle 
{
	import Common.GameAction;
	import Common.GameCreatureAction;
	import Common.GameDefine;
	import Common.MapDirection;
	
	import logic.GameCreatureData;

	/**
	 * ...
	 * @author ...
	 */
	public class BattleCreature 
	{
		public var actionHandler:GameCreatureAction = null;
		public var moveHandler:GameCreatureBattleMove = null;
		
		public var state:int = GameDefine.INVALIDID;
		public var data:GameCreatureData = null;
		
		public var ready:Boolean = false;
		
		public var action:int = GameDefine.INVALIDID;
		public var targetType:int = GameDefine.INVALIDID;
		public var targetIndex:int = GameDefine.INVALIDID;
		public var type:int = GameDefine.INVALIDID;
		public var index:int = GameDefine.INVALIDID;
		public var targetX:int = GameDefine.INVALIDID;
		public var targetY:int = GameDefine.INVALIDID;
		public var originX:int = GameDefine.INVALIDID;
		public var originY:int = GameDefine.INVALIDID;
		
//		public var x:int = GameDefine.INVALIDID;
//		public var y:int = GameDefine.INVALIDID;
		
		
		
		
		/////////////////////////////////////////////////////////////////////////////////////
		
		
		public function BattleCreature() 
		{
			
		}
		
		public function init( data:GameCreatureData ):void
		{
			if ( data ) 
			{
				this.data = data;
			}
			else
			{
				this.data = new GameCreatureData();
			}
			
			actionHandler = new GameCreatureAction();
			actionHandler.init( this );
			
			moveHandler = new GameCreatureBattleMove();
			moveHandler.init( this );
		}
		
		public function onEndMoving():void
		{
			
		}
		
		public function release():void
		{
			ready = false;
			data = null;
			actionHandler = null;
		}
		
		public function getPos():BattlePos
		{
			return moveHandler.pos;
		}
		
		public function setPos( x:int , y:int ):void
		{
			moveHandler.setPos( x , y );
		}
		
		public function isMoving():Boolean 
		{
			return moveHandler.moving;
		}
		
		public function move( x:int , y:int , fun:Function , b:Boolean = true ):void
		{
			moveHandler.setMovePos( x , y , fun , b );
			moveHandler.startMoving();
		}
		
		public function setMoveSpeed( speed:Number , acceleration:Number = 0.0 ):void
		{
			moveHandler.speed = speed;
			moveHandler.acceleration = acceleration;
		}
		
		
		//////////////////////////////////////////////////////////////////////////////////
		
		public function CheckState( s:int ):Boolean
		{
			return false;
		}
		
		public function setActionID( id:int ):void
		{
			actionHandler.setID( id );
		}
		
		public function setAction( id:int , fun:Function ):void
		{
			actionHandler.setAction( id , moveHandler.moveDirection , fun );
		}
		
		public function updateAction():void
		{
			actionHandler.update( GameAction.ACTIONDELAY );
		}
		
		public function getAction():int
		{
			return actionHandler.action;
		}
		
		public function get ActionTextureID():int
		{
			return actionHandler.textureID;
		}
		
		public function update( delay:Number ):void
		{
			actionHandler.update( delay );
			moveHandler.update( delay );
		}
		
		public function setDirection( dir:int ):void
		{
			moveHandler.moveDirection = dir;
		}
		
		public function Direction():int
		{
			return moveHandler.moveDirection;
		}
		
		public function isActionOver():Boolean
		{
			return actionHandler.isOver;
		}
		
		
	}

}